package cn.zjutleo.village_server.mapper;

import cn.zjutleo.village_server.entity.RepairApply;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: 张坤
 * @DateTime: 2021/8/28 21:58
 * @Description: 该类用于 报修查询
 */
public interface RepairApplyMapper {
    @Select("select * from repair_apply")
    @Results(id = "Base_repair_apply_data" , value = {
            @Result(property = "ra_id",  column = "ra_id",id = true),
            @Result(property = "ra_user_id",  column = "ra_user_id"),
            @Result(property = "ra_type",  column = "ra_type"),
            @Result(property = "ra_desc",  column = "ra_desc"),
            @Result(property = "ra_detail_address",  column = "ra_detail_address"),
            @Result(property = "ra_media_url",  column = "ra_media_url"),
            @Result(property = "ra_contact",  column = "ra_contact"),
            @Result(property = "ra_repair_date",  column = "ra_repair_date"),
            @Result(property = "ra_repair_time",  column = "ra_repair_time"),
            @Result(property = "ra_user_name",  column = "ra_user_name"),
            @Result(property = "ra_state",  column = "ra_state"),
            @Result(property = "ra_house_number",  column = "ra_house_number")
    })
    List<RepairApply> selectAll();


    int submitRepairInfo(RepairApply repairApply);

    @Select("select * from repair_apply where ra_id=#{id} ")
    @ResultMap("Base_repair_apply_data")
    RepairApply selectById(Integer id);

    @Select("select distinct ra_type from repair_apply")
    List<String> getAllRepairType();

    @Select("<script> " +
            "SELECT * " +
            "FROM repair_apply " +
            " <where> " +
            " <if test=\"date != null\">to_days(ra_apply_time) = to_days(#{date})</if> " +
            " <if test=\"type != null\"> AND ra_type=#{type}</if> " +
            " <if test=\"fuzzySearch != null\"> AND ra_desc like '%${fuzzySearch}%'</if> " +
            " </where> " +
            " </script> ")
    @ResultMap("Base_repair_apply_data")
    List<RepairApply> getRepairInfoFuzzySearch(String date,String type,String fuzzySearch);

    @Select("select u_role_id from user where u_id=#{id}")
    Integer getRoleRightById(Integer id);

    @Update("update repair_apply set ra_state=#{newRaState} where ra_id=#{ra_id} ")
    int updateRaState(int ra_id,int newRaState);
}
